package com.xiaozhi.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;

import com.thoughtworks.xstream.mapper.Mapper.Null;
import com.xiaozhi.common.context.UserTokenContextHolder;
import com.xiaozhi.common.web.AjaxResult;
import com.xiaozhi.entity.BussinessCombo;
import com.xiaozhi.entity.PersionCombo;
import com.xiaozhi.entity.SysUser;
import com.xiaozhi.service.BussinessComboService;
import com.xiaozhi.service.WxUserService;
import com.xiaozhi.vo.UserTokenVO;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;



@RestController
@AllArgsConstructor
@Slf4j
@RequestMapping("/wx/combo")
public class WxMaBussinessController {
    private final BussinessComboService bussinessComboService;

    private final WxUserService wxUserService;
    
    @GetMapping("/query")
    public Mono<AjaxResult> quary() {
        try {
            List<BussinessCombo> list = bussinessComboService.query(null);
            AjaxResult result = AjaxResult.success();
            result.put("data", list);
            return Mono.just(result);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Mono.just(AjaxResult.error());
        }
    }
    @GetMapping("/query/persion")
    public Mono<AjaxResult> quary_persion(ServerWebExchange exchange) {
        try {
            String token = UserTokenContextHolder.GetUserTokenFromWebExchange(exchange);;
            UserTokenVO user1 = wxUserService.getUserFromToken(token);
            List<PersionCombo> list = bussinessComboService.query_persion_combe(user1.getOpenId());
            AjaxResult result = AjaxResult.success();
            result.put("data", list);
            return Mono.just(result);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Mono.just(AjaxResult.error());
        }
    }

    @PostMapping("/test")
    public Mono<AjaxResult> quary1() {
        try {
            List<BussinessCombo> list = bussinessComboService.query(null);
            AjaxResult result = AjaxResult.success();
            result.put("data", list);
            return Mono.just(result);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Mono.just(AjaxResult.error());
        }
    }
    
}
